package jnBase.view
{
	import jnBase.Data;
	import jnBase.eventdispatcher.JNEventDispatcher;
	
	import laya.events.Event;
	import laya.ui.Box;
	import laya.ui.Image;
	import laya.ui.Label;
	import laya.utils.Handler;
	
	import ui.tools.wap.toolsDialogWAPUI;
	
	public class ToolsBoxWAP extends toolsDialogWAPUI
	{
		private var currtoolListData:Array;
		public function ToolsBoxWAP()
		{
			super();
		}
		override public function onAwake():void
		{
			// TODO Auto Generated method stub
			super.onAwake();
			dragArea="0,0,1511,116";
			// 使用但隐藏滚动条
			_list.renderHandler=new Handler(this,toolBoxRender);
			_list.mouseHandler=new Handler(this,onChooseTools);
			//滚动在头或底回弹时间
			_list.scrollBar.elasticBackTime= 500;
			//滚动在头或底最大距离
			_list.scrollBar.elasticDistance = 200;
			_list.scrollBar.autoHide=true;
			JNEventDispatcher.getInstance().on(JNEventDispatcher.ClOSE_TOOLS,this,function():void{
				this.close();
			})
			btn_Use.on(Event.CLICK,this,useThis);
		}
		
		private function useThis():void
		{
			// TODO Auto Generated method stub
			if(_list.selectedIndex!=-1){
				JNEventDispatcher.getInstance().event(JNEventDispatcher.CHOOSE_TOOLS,_list.selectedItem);
			}
		}
		/**
		 * 
		 * @param $ind 0显示实验器材  1显示药品试剂
		 * 
		 */		
		public function setData($ind:int=0):void{
			if($ind==0){
				title.text="实验器材";
				currtoolListData=Data.shiyanQiCai;
			}
			else if($ind==1){
				title.text="药品试剂";
				currtoolListData=Data.shiyanShiji;
			}
			_list.array=currtoolListData;
		}
		/**
		 *工具箱列表 Render
		 * 
		 */		
		private function toolBoxRender(cell:Box,ind:int):void
		{
			// TODO Auto Generated method stub
			var bg:Image=cell.getChildByName("btn").getChildByName("img") as Image;
			bg.skin=currtoolListData[ind].img;
			cell.name=currtoolListData[ind].title;
		}
		/**
		 *选中工具箱中的工具 
		 * @param e
		 * @param index
		 * 
		 */		
		private function onChooseTools(e:Event,index:int):void
		{
			// TODO Auto Generated method stub
//			if(e.type==Event.CLICK){//鼠标点击事件
//				//				trace("choose:"+index+currtoolListData[index].value);
//				JNEventDispatcher.getInstance().event(JNEventDispatcher.CHOOSE_TOOLS,currtoolListData[index]);
//			}
			if(e.type==Event.CLICK){
				_list.selectedIndex=index;
				currentSelect.skin=(_list.getCell(index).getChildByName("btn").getChildByName("img") as Image).skin;
				itemName.text=_list.getCell(index).name;
			}
		}
	}
}